/**
 * Created by dywu on 2015/9/24.
 */
angular.module('preferential.template', [
    'ngCookies'
])
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('preferential', {
            'abstract': true,
            url: "/uc",
            views: {
                '': {
                    template: '<div ui-view="topbar"></div><div ui-view="main"></div>'
                },
                'topbar@preferential': {
                    templateUrl: template_viewurl+"/topbar.html",
                    controller: 'PreferentialTopbarController'
                },
                'main@preferential': {
                    templateUrl: template_viewurl+"/main.html",
                    controller: 'PreferentialTemplateController'
                }
            }
        })
    ;
}])

//判断cookie
.controller('PreferentialTopbarController', ['$scope','$state','$cookieStore','LoginService', function($scope, $state, $cookieStore, LoginService) {
    //console.log('usercenter GetCookieController');
    var data = $cookieStore.get('manager_cookie');
    //console.log(data);
    if (data == undefined) {
        alert("登陆以失效，请再次登陆！");
        $state.go('login');
    } else {
        $scope.manager_cookie = data;
        //console.log("this is" + data.managername);
    }
    // topbar
    if (typeof topbars != 'undefined') {
        $scope.topbars = topbars;
    }
}])

//清除cookie
.controller('RemoveCookieController', ['$scope','$state','$cookieStore', function($scope, $state, $cookieStore) {
    console.log('RemoveCookieController');
    $cookieStore.remove('manager_cookie');
    $state.go('home.exit');
}])

//Mall模板
.controller('PreferentialTemplateController', ['$scope','$state', function($scope, $state) {
    //console.log('UsercenterTemplateController');
    $scope.sidebars=usercenter_sidebars;
    $scope.currentPage = 1;
    $scope.pageSize = 8;
}])
;
